package net.entelijan.cobean.tree;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class CobeanTreeCellRenderer extends DefaultTreeCellRenderer {

	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(CobeanTreeCellRenderer.class);

	public CobeanTreeCellRenderer() {
		super();
	}

	/**
	 * Delegates the creation of the render component to the CobeanTreeNode
	 */
	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		Component re;
		DefaultTreeCellRenderer rc = (DefaultTreeCellRenderer) super
				.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
						row, hasFocus);
		if (value instanceof CobeanTreeNode) {
			CobeanTreeNode ctn = (CobeanTreeNode) value;
			re = ctn.getTreeCellRendererComponent(rc, sel, expanded, leaf, row,
					hasFocus);
		} else {
			re = new JLabel("");
		}
		return re;
	}
}
